
local mt = ac.skill['眷族召唤']
mt.model1 = [[Abilities\Spells\Undead\AnimateDead\AnimateDeadTarget.mdl]]
local list = {'娜迦皇家卫士','娜迦小鱼人','娜迦小鱼人','娜迦小鱼人','娜迦小鱼人'}

function mt:add_unit()
    local hero = self.owner
    local enemy = ac.enemy
    if enemy then
        self.count = #list
        for a,name in ipairs(list) do
            local unit = self.unit[a]
            if unit==nil or not unit:is_alive() then
                local unit = enemy:add_unit(name,hero,true)
                unit['木材'] = 0
                unit:add_effect(self.model1):remove()
                self.unit[a] = unit
                unit:event '单位-受到伤害前'(function(_,_,_,data)
                    data:div(40)
                end)
                unit:event '单位-死亡'(function()
                    self.count = self.count - 1
                    if self.count<3 and hero:is_alive() then
                        self:add_unit()
                    end
                end)
                unit:add_buff '眷族'{source = hero}
            end
        end
    end
end

function mt:on_add()
    self.unit = {}
    self:add_unit()
end

local buff = ac.buff['眷族']
function buff:on_add()
    local source = self.source
    local unit = self.target
    self:gc(source:event '单位-死亡'(function()
        unit:remove()
    end))
end